home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / EXEC.SWG / 0005_Exec with Memory Shrink.pas < prev    next >
Pascal/Delphi Source File  |  1993-08-27  |  1KB  |  75 lines

  1. (*
  2. KELD R. HANSEN
  3.  
  4. > I need to *simulate* something like:
  5. > {$M 16384,0,0}               {reduce heap}
  6. > Exec('c:\myprgm.exe','');    {run myprgm.exe}
  7. > {$M 16384,110000,110000}     {restore heap}
  8.  
  9. EXECUTE shrinks your programs memory allocation to the smallest possible value,
  10. then runs the program and then expands it back up again. Works in TP 6.0 and
  11. 7.0!
  12. *)
  13.  
  14. USES
  15.   DOS;
  16.  
  17. TYPE
  18.   STR127 = STRING[127];
  19.  
  20. PROCEDURE ReallocateMemory(P : POINTER); ASSEMBLER;
  21. ASM
  22.   MOV  AX, PrefixSeg
  23.   MOV  ES, AX
  24.   MOV  BX, WORD PTR P+2
  25.   CMP  WORD PTR P,0
  26.   JE   @OK
  27.   INC  BX
  28.  
  29.  @OK:
  30.   SUB  BX, AX
  31.   MOV  AH, 4Ah
  32.   INT  21h
  33.   JC   @X
  34.   LES  DI, P
  35.   MOV  WORD PTR HeapEnd,DI
  36.   MOV  WORD PTR HeapEnd+2,ES
  37.  
  38.  @X:
  39. END;
  40.  
  41. FUNCTION EXECUTE(Name : PathStr ; Tail : STR127) : WORD; ASSEMBLER;
  42. ASM
  43.   {$IFDEF CPU386}
  44.   DB      66h
  45.   PUSH    WORD PTR HeapEnd
  46.   DB      66h
  47.   PUSH    WORD PTR Name
  48.   DB      66h
  49.   PUSH    WORD PTR Tail
  50.   DB      66h
  51.   PUSH    WORD PTR HeapPtr
  52.   {$ELSE}
  53.   PUSH    WORD PTR HeapEnd+2
  54.   PUSH    WORD PTR HeapEnd
  55.   PUSH    WORD PTR Name+2
  56.   PUSH    WORD PTR Name
  57.   PUSH    WORD PTR Tail+2
  58.   PUSH    WORD PTR Tail
  59.   PUSH    WORD PTR HeapPtr+2
  60.   PUSH    WORD PTR HeapPtr
  61.   {$ENDIF}
  62.   CALL ReallocateMemory
  63.   CALL SwapVectors
  64.   CALL DOS.EXEC
  65.   CALL SwapVectors
  66.   CALL ReallocateMemory
  67.   MOV  AX, DosError
  68.   OR   AX, AX
  69.   JNZ  @OUT
  70.   MOV  AH, 4Dh
  71.   INT  21h
  72.  
  73.  @OUT:
  74. END;
  75.